<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It is a breeze. Simply tell Lumen the URIs it should respond to
| and give it the Closure to call when that URI is requested.
|
*/

$router->group([
    'namespace' => 'Mobile',
    'prefix' => 'mini'
], function () use ($router) {

    $router->group(['prefix' => 'product'], function () use ($router) {
        $router->get('bank', 'ProductController@banks');
        $router->get('bank/{product_id}', 'ProductController@bankDetail');
        $router->get('fast', 'ProductController@fasts');
        $router->get('fast/{product_id}', 'ProductController@fastDetail');
    });

    $router->group(['prefix' => 'login'], function () use ($router) {
        $router->post('/', 'LoginController@login');
        $router->get('info', 'LoginController@info');
        $router->get('token', 'LoginController@getToken');
        $router->delete('/', 'LoginController@loginOut');
        $router->post('shop', ['uses' => 'LoginController@store', 'middleware' => 'miniauth']);
    });

//    $router->group(['prefix' => 'upload'], function () use ($router) {
//        $router->post('/', ['uses' => 'UploadController@upload', 'middleware' => 'adminauth:upload']);
//    });
//
//    $router->group(['prefix' => 'geo'], function () use ($router) {
//        $router->get('city', 'CityController@city');
//    });
});

$router->group([
    'namespace' => 'Shop',
    'prefix' => 'shop',
    'middleware' => 'shopauth'
], function () use ($router) {
    $router->group(['prefix' => 'shop'], function () use ($router) {
        $router->get('/', 'ShopController@show');
        $router->put('/', 'ShopController@update');
    });

    $router->group(['prefix' => 'product'], function () use ($router) {
        $router->get('/', 'ProductController@index');
        $router->get('{product_id}', 'ProductController@show');
        $router->post('/', 'ProductController@store');
        $router->put('/', 'ProductController@update');
        $router->delete('/', 'ProductController@del');
        $router->put('shelves', 'ProductController@shelves');
        $router->delete('sku', 'ProductController@delsku');
    });

    $router->group(['prefix' => 'category'], function () use ($router) {
        $router->get('/', 'CategoryController@index');
        $router->get('tree', 'CategoryController@tree');
        $router->get('template', 'CategoryController@template');
        $router->get('treenameids', 'CategoryController@treeNameIds');
    });
});

$router->group([
    'namespace' => 'Api',
    'prefix' => 'api'
], function () use ($router) {
    $router->group(['prefix' => 'captcha'], function () use ($router) {
        $router->get('info', 'CaptchaController@info');
        $router->get('image/{type}/{uuid}', 'CaptchaController@image');
    });

    $router->group(['prefix' => 'upload'], function () use ($router) {
        $router->post('/', ['uses' => 'UploadController@upload', 'middleware' => 'apiauth']);
    });

    $router->group(['prefix' => 'geo'], function () use ($router) {
        $router->get('city', 'CityController@city');
    });

    $router->get('alg', 'AlgorithmController@index');
});


$router->group([
    'namespace' => 'Admin',
    'prefix' => 'admin',
    'middleware' => 'lang'
], function () use ($router) {

    $router->group(['namespace' => 'Test', 'prefix' => 'test'], function () use ($router) {
        $router->get('/', 'TestController@index');
    });


    $router->group(['namespace' => 'Auth', 'prefix' => 'auth',], function () use ($router) {
        $router->post('login', 'LoginController@login');
        $router->get('info', ['uses' => 'LoginController@info', 'middleware' => 'adminauth']);
        $router->post('loginout', ['uses' => 'LoginController@loginout', 'middleware' => 'adminauth']);
        $router->post('register', 'LoginController@register');

        /**
         * 管理员
         */
        $router->group(['prefix' => 'admin'], function () use ($router) {
            $router->get('/', ['uses' => 'AdminController@index', 'middleware' => 'adminauth:admin_index']);
            $router->get('{admin_id}', ['uses' => 'AdminController@show', 'middleware' => 'adminauth:admin_show']);
            $router->post('/', ['uses' => 'AdminController@store', 'middleware' => 'adminauth:admin_store']);
            $router->put('/', ['uses' => 'AdminController@save', 'middleware' => 'adminauth:admin_save']);
            $router->put('info', ['uses' => 'AdminController@info', 'middleware' => 'adminauth:admin_info']);
            $router->delete('/', ['uses' => 'AdminController@del', 'middleware' => 'adminauth:admin_del']);
        });


        /**
         * 角色
         */
        $router->group(['prefix' => 'role'], function () use ($router) {
            $router->get('/', ['uses' => 'RoleController@index', 'middleware' => 'adminauth:role_index']);
            $router->get('{role_id}', ['uses' => 'RoleController@show', 'middleware' => 'adminauth:role_show']);
            $router->post('/', ['uses' => 'RoleController@store', 'middleware' => 'adminauth:role_store']);
            $router->put('/', ['uses' => 'RoleController@save', 'middleware' => 'adminauth:role_save']);
            $router->put('status', ['uses' => 'RoleController@saveStatus', 'middleware' => 'adminauth:role_save']);
            $router->delete('{role_id}', ['uses' => 'RoleController@del', 'middleware' => 'adminauth:role_del']);
        });

        /**
         * 权限
         */
        $router->group(['prefix' => 'permission'], function () use ($router) {
            $router->get('/', ['uses' => 'PermissionController@index', 'middleware' => 'adminauth:permission_index']);
            $router->get('list', ['uses' => 'PermissionController@lists', 'middleware' => 'adminauth:permission_index']);
            $router->get('{permission_id}', ['uses' => 'PermissionController@show', 'middleware' => 'adminauth:permission_show']);
            $router->post('/', ['uses' => 'PermissionController@store', 'middleware' => 'adminauth:permission_store']);
            $router->put('/', ['uses' => 'PermissionController@save', 'middleware' => 'adminauth:permission_save']);
            $router->delete('{permission_id}', ['uses' => 'PermissionController@del', 'middleware' => 'adminauth:permission_del']);
        });

    });


    $router->group(['namespace' => 'Product', 'prefix' => 'product',], function () use ($router) {

        /**
         *
         */
        $router->group(['prefix' => 'attribue'], function () use ($router) {
            $router->get('/', ['uses' => 'AttrbueController@index', 'middleware' => 'adminauth:attr_index']);
            $router->get('{attr_id}', ['uses' => 'AttrbueController@show', 'middleware' => 'adminauth:attr_show']);
            $router->post('/', ['uses' => 'AttrbueController@store', 'middleware' => 'adminauth:attr_store']);
            $router->put('/', ['uses' => 'AttrbueController@update', 'middleware' => 'adminauth:attr_save']);
            $router->delete('/', ['uses' => 'AttrbueController@deleteAttrName', 'middleware' => 'adminauth:attr_del']);
            $router->delete('delval', ['uses' => 'AttrbueController@delAttrVal', 'middleware' => 'adminauth:attr_delval']);
        });

        /**
         *
         */
        $router->group(['prefix' => 'category'], function () use ($router) {
            $router->get('/', ['uses' => 'CategoryController@index', 'middleware' => 'adminauth:cat_index']);
            $router->get('tree', ['uses' => 'CategoryController@tree', 'middleware' => 'adminauth:cat_index']);
            $router->get('treenameids', ['uses' => 'CategoryController@treeNameIds', 'middleware' => 'adminauth:cat_getname']);
            $router->get('{cat_id}', ['uses' => 'CategoryController@show', 'middleware' => 'adminauth:cat_show']);
            $router->post('/', ['uses' => 'CategoryController@store', 'middleware' => 'adminauth:cat_store']);
            $router->put('/', ['uses' => 'CategoryController@update', 'middleware' => 'adminauth:cat_save']);
            $router->delete('{cat_id}', ['uses' => 'CategoryController@delete', 'middleware' => 'adminauth:cat_del']);
        });


        $router->group(['prefix' => 'brand'], function () use ($router) {
            $router->get('/', ['uses' => 'BrandController@index', 'middleware' => 'adminauth:brand_index']);
            $router->get('{brand_id}', ['uses' => 'BrandController@show', 'middleware' => 'adminauth:brand_show']);
            $router->post('/', ['uses' => 'BrandController@store', 'middleware' => 'adminauth:brand_store']);
            $router->put('/', ['uses' => 'BrandController@update', 'middleware' => 'adminauth:brand_save']);
            $router->delete('/', ['uses' => 'BrandController@delete', 'middleware' => 'adminauth:brand_del']);
        });

        $router->group(['prefix' => 'product'], function () use ($router) {
            $router->get('/', ['uses' => 'ProductController@index', 'middleware' => 'adminauth:product_index']);
            $router->get('{product_id}', ['uses' => 'ProductController@show', 'middleware' => 'adminauth:product_show']);
            $router->put('/', ['uses' => 'ProductController@checked', 'middleware' => 'adminauth:product_save']);
        });

        $router->group(['prefix' => 'template'], function () use ($router) {
            $router->get('/', ['uses' => 'TemplateController@index', 'middleware' => 'adminauth:template_index']);
            $router->get('{template_id}', ['uses' => 'TemplateController@show', 'middleware' => 'adminauth:template_show']);
            $router->put('/', ['uses' => 'TemplateController@update', 'middleware' => 'adminauth:template_save']);
            $router->post('/', ['uses' => 'TemplateController@store', 'middleware' => 'adminauth:template_store']);
            $router->delete('/', ['uses' => 'TemplateController@delete', 'middleware' => 'adminauth:template_del']);
        });

    });

    $router->group(['namespace' => 'Shop', 'prefix' => 'shop'], function () use ($router) {
        $router->group(['prefix' => 'shop'], function () use ($router) {
            $router->get('/', ['uses' => 'ShopController@shop', 'middleware' => 'adminauth:shop_shops']);
            $router->get('index', ['uses' => 'ShopController@index', 'middleware' => 'adminauth:shop_index']);
            $router->get('{shop_id}', ['uses' => 'ShopController@show', 'middleware' => 'adminauth:shop_show']);
            $router->put('/', ['uses' => 'ShopController@update', 'middleware' => 'adminauth:shop_update']);
        });
    });

    $router->group(['namespace' => 'Order', 'prefix' => 'user',], function () use ($router) {
        $router->group(['prefix' => 'rule'], function () use ($router) {
            $router->get('/', ['uses' => 'RuleController@index', 'middleware' => 'adminauth:rule_index']);
            $router->get('{rule_id}', ['uses' => 'RuleController@show', 'middleware' => 'adminauth:rule_show']);
            $router->post('/', ['uses' => 'RuleController@store', 'middleware' => 'adminauth:rule_store']);
            $router->put('/', ['uses' => 'RuleController@save', 'middleware' => 'adminauth:rule_save']);
            $router->delete('/', ['uses' => 'RuleController@del', 'middleware' => 'adminauth:rule_del']);
        });
    });


    $router->group(['namespace' => 'System', 'prefix' => 'sys',], function () use ($router) {
        $router->group(['prefix' => 'conf'], function () use ($router) {
            $router->get('/', ['uses' => 'ConfigController@index', 'middleware' => 'adminauth:config_index']);
            $router->get('show', ['uses' => 'ConfigController@show', 'middleware' => 'adminauth:config_show']);
            $router->post('/', ['uses' => 'ConfigController@store', 'middleware' => 'adminauth:config_store']);
            $router->put('/', ['uses' => 'ConfigController@save', 'middleware' => 'adminauth:config_save']);
        });
    });

    $router->group(['namespace' => 'Ad', 'prefix' => 'ad',], function () use ($router) {
        $router->group(['prefix' => 'ad'], function () use ($router) {
            $router->get('/', ['uses' => 'AdController@index', 'middleware' => 'adminauth:ad_index']);
            $router->post('/', ['uses' => 'AdController@store', 'middleware' => 'adminauth:ad_store']);
            $router->put('/', ['uses' => 'AdController@save', 'middleware' => 'adminauth:ad_save']);
            $router->delete('/', ['uses' => 'AdController@del', 'middleware' => 'adminauth:ad_del']);
        });

        $router->group(['prefix' => 'position'], function () use ($router) {
            $router->get('/', ['uses' => 'PositionController@index', 'middleware' => 'adminauth:position_index']);
            $router->get('{}', ['uses' => 'PositionController@show', 'middleware' => 'adminauth:position_show']);
            $router->post('/', ['uses' => 'PositionController@store', 'middleware' => 'adminauth:position_store']);
            $router->put('/', ['uses' => 'PositionController@save', 'middleware' => 'adminauth:position_save']);
            $router->delete('/', ['uses' => 'PositionController@del', 'middleware' => 'adminauth:position_del']);
        });
    });


});